package com.specter.dev.code.execute;

import lombok.extern.slf4j.Slf4j;

/**
 * Note:
 * 
 * @author Liang.Wang
 * @version Mar 23, 2017
 */
@Slf4j
public class ModuleInputExeFactory {
	
	private ModuleInputExeFactory() {
	}

	public static ModuleInputExe create(String type) {
		if ("".equals(type) || type == null) {
			log.error("The module input link type is null !");
			return null;
		}

		ModuleInputExe input = null;
		String inputClass = ModuleInputExe.class.getName() + "4" + Character.toUpperCase(type.charAt(0)) + type.substring(1);
		try {
			Class<?> clazz = Class.forName(inputClass);
			if (ModuleInputExe.class.isAssignableFrom(clazz)) {
				input = (ModuleInputExe) clazz.getDeclaredConstructor().newInstance();
			}
		} catch (Exception e) {
			log.error("Class : {} is not found", inputClass);
		}

		if (input == null) {
			log.error("The module input implements is not defined.");
		}
		return input;
	}
}
